package com.ds.app.proxy;


import com.ds.app.App;
import com.ds.app.Module;
import com.ds.app.filter.AppFilter;
import com.ds.app.filter.ModuleFilter;

import java.util.ArrayList;
import java.util.List;

public class AppProxy implements App{
	public App app;
	public AppFilter appFilter; 
	public ModuleFilter moduleFilter;
	private List childIdList;
	private List moduleIdList;
	public AppProxy(App app,AppFilter appFilter,ModuleFilter moduleFilter){
		this.app=app;
		this.appFilter=appFilter;
		this.moduleFilter=moduleFilter;
	}

	public int compareTo(App o) {
		return app.compareTo(o);
	}

	public List<App> getAllParent() {
		return app.getAllParent();
	}

	public String getBrief() {
		return app.getBrief();
	}

	public List<String> getChildIdList() {
		
		List<String>  appIdList=new ArrayList<String>();
		List<App> cappList=this.getChildrenList();
		for(int k=0;k<cappList.size();k++){
			App appProxy=cappList.get(k);
			if (app.getChildrenList().contains(appProxy.getID())){
				appIdList.add(appProxy.getID());
			}
		}
		return appIdList;
	}

	public List<App> getChildrenList() {
		List<App>  appList=new ArrayList<App>();
		List<App> cappList=app.getChildrenList();
		for(int k=0;k<cappList.size();k++){
			App app=cappList.get(k);
			if (appFilter==null || appFilter.filterObject(app,this.moduleFilter)){
				if (!appList.contains(app)){
					appList.add(app);
				}
			}
		}
		return appList;
	}

	public List<App> getChildrenRecursivelyList() {
		List<App>  appList=new ArrayList<App>();
		List<App> cappList=this.getChildrenList();
		for(int k=0;k<cappList.size();k++){
			App app=cappList.get(k);
			List<App> dappList=app.getChildrenRecursivelyList();
			for(int j=0;j<dappList.size();j++){
				App dapp=dappList.get(k);
				if (appFilter==null || appFilter.filterObject(dapp,this.moduleFilter)){
					if (!appList.contains(app)){
						appList.add(app);
					}
				}
			}
		}
		
		return appList;
	}

	public String getID() {
		return app.getID();
	}

	public Integer getIndex() {
		return app.getIndex();
	}

	public List<String> getModuleIdList() {
		List<String>  moduleIdList=new ArrayList<String>();
		List<Module> cmoduleList=this.getModuleList();
		for(int k=0;k<cmoduleList.size();k++){
			Module moduleProxy=cmoduleList.get(k);
			if (app.getChildrenList().contains(moduleProxy.getID())){
				moduleIdList.add(moduleProxy.getID());
			}
		}
		return moduleIdList;
	}
	

	public List<Module> getModuleList() {
		List<Module>  moduleList=new ArrayList<Module>();
		List<Module> cmoduleList=app.getModuleList();
		for(int k=0;k<cmoduleList.size();k++){
			Module module=cmoduleList.get(k);
			if (moduleFilter==null || moduleFilter.filterObject(module,null)){
				if (!moduleList.contains(module)){
					moduleList.add(module);
				}
			}
		}
	return moduleList;
	}
	

	public List<Module> getModuleListRecursively() {
		List<Module>  moduleList=new ArrayList<Module>();
		List<Module> cmoduleList=app.getModuleListRecursively();
		for(int k=0;k<cmoduleList.size();k++){
			Module module=cmoduleList.get(k);
			if (moduleFilter==null || moduleFilter.filterObject(module,null)){
				if (!moduleList.contains(module)){
					moduleList.add(module);
				}
				
			}
		}
		return moduleList;
	}
	

	public String getName() {
		return app.getName();
	}

	public App getParent() {
		return app.getParent();
	}

	public String getParentId() {
		return app.getParentId();
	}

	public int getTier() {
		return app.getTier();
	}

	
	public String getIcon() {
	
		return app.getIcon();
	}
	
	
}
